package com.my.action;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import com.my.common.I18nAssember;

/**
 * 用于跳转页面
 * 
 * @author wb-zc189961
 *
 */
@Controller
@RequestMapping(value="/local")
public class ExchangeLocalAction {
	private static final Logger logger = LoggerFactory.getLogger(ExchangeLocalAction.class);
	@RequestMapping(value = "/exchange_local", method = { RequestMethod.GET })
	public String exchangeLocal(
			HttpServletRequest request,
			@RequestParam(value = "langType", defaultValue = "zh") String langType,@RequestParam(value = "url", defaultValue = "index.do") String url) {
			if (langType.equals("zh")) {
				Locale locale = new Locale("zh", "CN");
				request.getSession()
						.setAttribute(
								SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,
								locale);
			} else if (langType.equals("en")) {
				Locale locale = new Locale("en", "US");
				request.getSession()
						.setAttribute(
								SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,
								locale);
			} else {
				request.getSession().setAttribute(
						SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,
						LocaleContextHolder.getLocale());
			}
			I18nAssember.assemberI18n(request);
			return "redirect:"+url;
	}
}